<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>管理员仪表盘 - 物流订单跟踪系统</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css">
    <link rel="stylesheet" href="/css/theme.css">
    <style>
        body {
            min-height: 100vh;
            background-color: var(--bg-color);
        }
        .sidebar {
            position: fixed;
            top: 0;
            bottom: 0;
            left: 0;
            z-index: 100;
            padding: 48px 0 0;
            box-shadow: var(--box-shadow);
            background-color: var(--card-bg);
        }
        .sidebar-sticky {
            position: relative;
            top: 0;
            height: calc(100vh - 48px);
            padding-top: .5rem;
            overflow-x: hidden;
            overflow-y: auto;
        }
        .nav-link {
            font-weight: 500;
            color: var(--text-color);
        }
        .nav-link.active {
            color: var(--primary-color);
        }
        main {
            padding-top: 48px;
        }
        .card {
            background-color: var(--card-bg);
            border-radius: var(--border-radius);
            box-shadow: var(--box-shadow);
            margin-bottom: 1rem;
        }
        .dashboard-card {
            transition: transform 0.3s;
        }
        .dashboard-card:hover {
            transform: translateY(-5px);
        }
    </style>
</head>
<body>
    <header class="navbar navbar-dark sticky-top bg-dark flex-md-nowrap p-0 shadow">
        <a class="navbar-brand col-md-3 col-lg-2 me-0 px-3" href="#">物流订单系统管理后台</a>
        <button class="navbar-toggler position-absolute d-md-none collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#sidebarMenu">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="w-100"></div>
        <div class="navbar-nav">
            <div class="nav-item text-nowrap">
                <a class="nav-link px-3" href="#" id="logoutBtn"><i class="bi bi-box-arrow-right"></i> 退出登录</a>
            </div>
        </div>
    </header>

    <div class="container-fluid">
        <div class="row">
            <nav id="sidebarMenu" class="col-md-3 col-lg-2 d-md-block sidebar collapse">
                <div class="sidebar-sticky pt-3">
                    <ul class="nav flex-column">
                        <li class="nav-item">
                            <a class="nav-link active" href="#" id="dashboardLink">
                                <i class="bi bi-speedometer2"></i> 仪表盘
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="#" id="usersLink">
                                <i class="bi bi-people"></i> 用户管理
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="#" id="deliveryPersonsLink">
                                <i class="bi bi-bicycle"></i> 配送员管理
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="#" id="ordersLink">
                                <i class="bi bi-box-seam"></i> 订单管理
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="#" id="statisticsLink">
                                <i class="bi bi-bar-chart"></i> 统计分析
                            </a>
                        </li>
                    </ul>
                </div>
            </nav>

            <main class="col-md-9 ms-sm-auto col-lg-10 px-md-4">
                <!-- 仪表盘视图 -->
                <div id="dashboardView">
                    <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
                        <h1 class="h2">仪表盘</h1>
                        <div class="btn-toolbar mb-2 mb-md-0">
                            <button type="button" class="btn btn-sm btn-outline-secondary" id="refreshDashboard">
                                <i class="bi bi-arrow-repeat"></i> 刷新
                            </button>
                        </div>
                    </div>

                    <div class="row">
                        <div class="col-md-3 mb-4">
                            <div class="card dashboard-card text-center p-3">
                                <div class="card-body">
                                    <i class="bi bi-people fs-1 text-primary"></i>
                                    <h5 class="card-title mt-3">用户总数</h5>
                                    <p class="card-text fs-2" id="totalUsers">0</p>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-3 mb-4">
                            <div class="card dashboard-card text-center p-3">
                                <div class="card-body">
                                    <i class="bi bi-bicycle fs-1 text-success"></i>
                                    <h5 class="card-title mt-3">配送员总数</h5>
                                    <p class="card-text fs-2" id="totalDeliveryPersons">0</p>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-3 mb-4">
                            <div class="card dashboard-card text-center p-3">
                                <div class="card-body">
                                    <i class="bi bi-box-seam fs-1 text-warning"></i>
                                    <h5 class="card-title mt-3">订单总数</h5>
                                    <p class="card-text fs-2" id="totalOrders">0</p>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-3 mb-4">
                            <div class="card dashboard-card text-center p-3">
                                <div class="card-body">
                                    <i class="bi bi-check-circle fs-1 text-info"></i>
                                    <h5 class="card-title mt-3">已完成订单</h5>
                                    <p class="card-text fs-2" id="completedOrders">0</p>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="row">
                        <div class="col-md-6">
                            <div class="card">
                                <div class="card-header">
                                    <h5 class="card-title mb-0">最近订单</h5>
                                </div>
                                <div class="card-body">
                                    <div class="table-responsive">
                                        <table class="table table-striped table-sm">
                                            <thead>
                                                <tr>
                                                    <th>订单号</th>
                                                    <th>状态</th>
                                                    <th>创建时间</th>
                                                    <th>操作</th>
                                                </tr>
                                            </thead>
                                            <tbody id="recentOrdersTable">
                                                <!-- 最近订单数据将通过JavaScript填充 -->
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="card">
                                <div class="card-header">
                                    <h5 class="card-title mb-0">配送员状态</h5>
                                </div>
                                <div class="card-body">
                                    <div class="table-responsive">
                                        <table class="table table-striped table-sm">
                                            <thead>
                                                <tr>
                                                    <th>姓名</th>
                                                    <th>电话</th>
                                                    <th>状态</th>
                                                    <th>操作</th>
                                                </tr>
                                            </thead>
                                            <tbody id="deliveryPersonsTable">
                                                <!-- 配送员数据将通过JavaScript填充 -->
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- 其他视图将在这里添加，如用户管理、配送员管理、订单管理等 -->
                <div id="usersView" style="display: none;">
                    <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
                        <h1 class="h2">用户管理</h1>
                        <div class="btn-toolbar mb-2 mb-md-0">
                            <button type="button" class="btn btn-sm btn-outline-secondary" id="refreshUsers">
                                <i class="bi bi-arrow-repeat"></i> 刷新
                            </button>
                        </div>
                    </div>
                    
                    <div class="card">
                        <div class="card-body">
                            <div class="table-responsive">
                                <table class="table table-striped table-hover">
                                    <thead>
                                        <tr>
                                            <th>ID</th>
                                            <th>用户名</th>
                                            <th>角色</th>
                                            <th>操作</th>
                                        </tr>
                                    </thead>
                                    <tbody id="usersTable">
                                        <!-- 用户数据将通过JavaScript填充 -->
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>

                <div id="deliveryPersonsView" style="display: none;">
                    <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
                        <h1 class="h2">配送员管理</h1>
                        <div class="btn-toolbar mb-2 mb-md-0">
                            <button type="button" class="btn btn-sm btn-outline-secondary" id="refreshDeliveryPersons">
                                <i class="bi bi-arrow-repeat"></i> 刷新
                            </button>
                        </div>
                    </div>
                    
                    <div class="card">
                        <div class="card-body">
                            <div class="table-responsive">
                                <table class="table table-striped table-hover">
                                    <thead>
                                        <tr>
                                            <th>ID</th>
                                            <th>姓名</th>
                                            <th>电话</th>
                                            <th>状态</th>
                                            <th>操作</th>
                                        </tr>
                                    </thead>
                                    <tbody id="deliveryPersonsFullTable">
                                        <!-- 配送员数据将通过JavaScript填充 -->
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>

                <div id="ordersView" style="display: none;">
                    <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
                        <h1 class="h2">订单管理</h1>
                        <div class="btn-toolbar mb-2 mb-md-0">
                            <button type="button" class="btn btn-sm btn-outline-secondary" id="refreshOrders">
                                <i class="bi bi-arrow-repeat"></i> 刷新
                            </button>
                        </div>
                    </div>
                    
                    <div class="card">
                        <div class="card-body">
                            <div class="table-responsive">
                                <table class="table table-striped table-hover">
                                    <thead>
                                        <tr>
                                            <th>订单号</th>
                                            <th>发件人</th>
                                            <th>收件人</th>
                                            <th>状态</th>
                                            <th>创建时间</th>
                                            <th>操作</th>
                                        </tr>
                                    </thead>
                                    <tbody id="ordersTable">
                                        <!-- 订单数据将通过JavaScript填充 -->
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>

                <div id="statisticsView" style="display: none;">
                    <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
                        <h1 class="h2">统计分析</h1>
                        <div class="btn-toolbar mb-2 mb-md-0">
                            <button type="button" class="btn btn-sm btn-outline-secondary" id="refreshStatistics">
                                <i class="bi bi-arrow-repeat"></i> 刷新
                            </button>
                        </div>
                    </div>
                    
                    <div class="row">
                        <div class="col-md-6 mb-4">
                            <div class="card">
                                <div class="card-header">
                                    <h5 class="card-title mb-0">订单状态分布</h5>
                                </div>
                                <div class="card-body">
                                    <div id="orderStatusChart" style="height: 300px;"></div>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6 mb-4">
                            <div class="card">
                                <div class="card-header">
                                    <h5 class="card-title mb-0">配送员状态分布</h5>
                                </div>
                                <div class="card-body">
                                    <div id="deliveryPersonStatusChart" style="height: 300px;"></div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </main>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
    <div id="alertPlaceholder" class="position-fixed top-0 end-0 p-3" style="z-index: 5000;"></div>
    <!-- 只保留这一行 -->
    <script src="/js/admin/dashboard.js"></script>

    <!-- 订单状态修改模态框 -->
    <div class="modal fade" id="updateStatusModal" tabindex="-1" aria-labelledby="updateStatusModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="updateStatusModalLabel">修改订单状态</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body">
                    <form id="updateStatusForm">
                        <input type="hidden" id="statusOrderNumber">
                        <div class="mb-3">
                            <label for="newStatus" class="form-label">新状态</label>
                            <select class="form-select" id="newStatus" required>
                                <option value="PENDING_PAYMENT">待支付</option>
                                <option value="PENDING_COLLECTION">待揽收</option>
                                <option value="COLLECTED">已揽收</option>
                                <option value="TRANSPORTING">运输中</option>
                                <option value="OUT_FOR_DELIVERY">派送中</option>
                                <option value="DELIVERY_FAILED">派送失败</option>
                                <option value="SIGNED">已签收</option>
                                <option value="COMPLETED">已完成</option>
                                <option value="CANCELLED">已取消</option>
                                <option value="REFUNDED">已退款</option>
                            </select>
                        </div>
                        <div class="mb-3">
                            <label for="statusDescription" class="form-label">备注说明</label>
                            <textarea class="form-control" id="statusDescription" rows="3" placeholder="可选：添加状态变更的备注说明"></textarea>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
                    <button type="button" class="btn btn-primary" id="updateStatusBtn">保存</button>
                </div>
            </div>
        </div>
    </div>

    <!-- 分配配送员模态框 -->
    <div class="modal fade" id="assignModal" tabindex="-1" aria-labelledby="assignModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="assignModalLabel">分配配送员</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body">
                    <form id="assignForm">
                        <input type="hidden" id="assignOrderNumber">
                        <div class="mb-3">
                            <label for="deliveryPersonId" class="form-label">选择配送员</label>
                            <select class="form-select" id="deliveryPersonId" required>
                                <option value="">-- 请选择配送员 --</option>
                                <!-- 配送员列表将通过JavaScript填充 -->
                            </select>
                        </div>
                    </form>
                    <!-- 移除自动分配按钮 -->
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
                    <button type="button" class="btn btn-primary" id="assignBtn">确认分配</button>
                </div>
            </div>
        </div>
    </div>
</body>
</html>